package com.xgame.controller;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.xgame.poto.BasePacket.Packet;
import com.xgame.poto.UserProto.UserPb;
import com.xgame.service.UserService;

@Controller
@RequestMapping("/test")
public class TestController extends BaseController {
	@Autowired
	UserService userService;

	@RequestMapping(value = "/get", method = RequestMethod.GET)
	@ResponseBody
	public UserPb get() throws IOException {
		log.info("get进来了");
		UserPb.Builder userPb = UserPb.newBuilder().setUserName("赵巍");
		// PhoneNumber value=PhoneNumber.newBuilder().setNumber("22").build();
		// userPb.addPhone(value);
		log.info(userPb.build().toString());
		return userPb.build();
	}

	@RequestMapping(value = "/connected", method = RequestMethod.POST)
	@ResponseBody
	public Packet.Builder connected(@RequestBody UserPb useClientInfo)
			throws IOException {
		Packet.Builder packetBuilder = Packet.newBuilder();
		// log.info("服务端收到:"+useClientInfo.toString());
		log.info(useClientInfo.getUserName() + "进来了");
		UserPb.Builder userPb = UserPb.newBuilder().setUserName("返回的名字ok");
		packetBuilder.setData(userPb.build().toByteString());
		return packetBuilder;
	}

//	@RequestMapping(value = "/json", method = RequestMethod.GET)
//	@ResponseBody
//	public List<User> json() throws IOException {
//		// log.info("服务端收到:"+useClientInfo.toString());
//		log.info("json进来了");
//		UserPb.Builder userPb = UserPb.newBuilder().setUserName("返回的名字ok");
//		// userPb.addPhone(value);
//		// log.info(userPb.toString());
//		List<User> a = new ArrayList<>();
//		for (int i = 0; i < 99999; i++) {
//			User user = new User();
//			String s = "test";
//			for (int j = 0; j < 999; j++) {
//				s = "test" + j;
//			}
//			user.setCityName("多个多个" + i);
//			user.setNickName("name");
//			user.setAddress("addressaddressaddressaddressaddressaddressaddressaddressaddressaddressaddressaddress");
//			user.setAge(s);
//			a.add(user);
//		}
//		return a;
//	}

	// @ResponseBody
	// @RequestMapping("getuser")
	// public UserPb getUseClientInfo(HttpServletResponse response) throws
	// IOException{
	// UserPb.Builder useClientInfoBuilder = UserPb.newBuilder();
	// log.info(useClientInfoBuilder.toString());
	// // ……业务逻辑略……
	// return useClientInfoBuilder.build();
	// }
}
